package com.pshcp.doctor.api;

import com.alibaba.fastjson.JSON;
import com.framework.base.PageList;
import com.framework.base.ResultBuilder;
import com.framework.base.ResultDTO;
import com.framework.exception.BizException;
import com.framework.logaop.Log;
import com.framework.logaop.LogSourceEnum;
import com.framework.logaop.LogTypeEnum;
import com.framework.thread.ReqComHold;
import com.framework.tool.CommonTool;
import com.framework.util.DateUtil;
import com.pshcp.doctor.ao.sendmessage.DoctorSendMessagePageAO;
import com.pshcp.doctor.ao.statistics.DataSummaryAO;
import com.pshcp.doctor.tool.DoctorSendMessageTool;
import com.pshcp.doctor.tool.DoctorStatisticsTool;
import com.pshcp.doctor.vo.sendmessage.DoctorSendMessageContentVO;
import com.pshcp.doctor.vo.statistics.DataSummaryExplainVO;
import com.pshcp.doctor.vo.statistics.DataSummaryVO;
import com.pshcp.domain.dto.DoctorSendMessageContentDTO;
import com.pshcp.domain.model.DoctorSendMessageContent;
import com.pshcp.domain.model.OnlineSession;
import com.pshcp.service.OnlineSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2023/3/15 00:32
 */
@Api(tags = {"医生端-统计"})
@Slf4j
@RestController
@RequestMapping("/api/doctor/statistics")
public class DoctorStatisticsAPI {

    @Value("${custom.data-summary-explain}")
    private String dataSummaryExplain;

    @Autowired
    private OnlineSessionService onlineSessionService;

    @ApiOperation("数据中心")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.SELECT, desc = "数据中心")
    @PostMapping("getDataSummary")
    public ResultDTO<List<DataSummaryVO>> getDataSummary(@RequestBody DataSummaryAO dataSummaryAO) throws BizException {
        CommonTool.checkObj(dataSummaryAO.getSyear(), "90000006");
        CommonTool.checkObj(dataSummaryAO.getSmm(), "90000006");
        CommonTool.checkObj(dataSummaryAO.getSdd(), "90000006");
        CommonTool.checkObj(dataSummaryAO.getEyear(), "90000006");
        CommonTool.checkObj(dataSummaryAO.getEmm(), "90000006");
        CommonTool.checkObj(dataSummaryAO.getEdd(), "90000006");
        List<String> timePeriodFromTwoTimeList = DateUtil.getTimePeriodFromTwoTimeList(dataSummaryAO.getSyear(), dataSummaryAO.getSmm(), dataSummaryAO.getSdd(),
                dataSummaryAO.getEyear(), dataSummaryAO.getEmm(), dataSummaryAO.getEdd());
        String startTime = timePeriodFromTwoTimeList.get(0);
        String endTime = timePeriodFromTwoTimeList.get(timePeriodFromTwoTimeList.size() - 1);
        Integer wzlCount = onlineSessionService.getOnlineSessionCount2Wzl(ReqComHold.getReqCom().getUserId(), startTime, endTime);
        List<DataSummaryVO> list = DoctorStatisticsTool.buildGetDataSummary(  wzlCount);
        return ResultBuilder.success(list);
    }

    @ApiOperation("数据说明")
    @Log(source = LogSourceEnum.APP, type = LogTypeEnum.SELECT, desc = "数据说明")
    @PostMapping("getDataSummaryExplain")
    public ResultDTO<List<DataSummaryExplainVO>> getDataSummaryExplain() throws BizException {
        List<DataSummaryExplainVO> list = JSON.parseArray(dataSummaryExplain, DataSummaryExplainVO.class);
        return ResultBuilder.success(list);
    }

}
